<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>功能管理</title>
<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/basic/function/dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'menu',
				title : '所属菜单',
				sortable : true,
				formatter : function(value, row, index) {
					return row.menuName;
				}
			}, {
				field : 'functionName',
				title : '功能名称',
				sortable : true
			}, {
				field : 'functionNo',
				title : '功能编号',
				sortable : true
			}, {
				field : 'otherRights',
				title : '其他权限',
				sortable : true
			} ] ]

		}));

		$grid.datagrid('enableFilter', [ {
			field : 'menu',
			searchField : 'menu.menuName'
		} ]);
		$("#excelExport").click(function() {
			var url = "${ctx}/basic/function/excelExport?" + $.param($("#grid").datagrid('options').queryParams);
			if ($("#grid").datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($("#grid").datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "function",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
	});

	function fun_function_add() {
		$("#dlg").dialog("open").dialog("setTitle", "新增功能");
		$("#fm").form("clear");
	}

	function fun_function_edit() {
		var row = $("#grid").datagrid("getSelected");
		if (row == null) {
			showAlert("您未选择任何记录!");
		} else {
			$("#dlg").dialog("open").dialog("setTitle", "编辑功能--[" + row.functionName + "]");
			$("#fm").form("load", row);
		}
	}

	function fun_function_del() {
		multiDeleteDataGrid($grid, "${ctx}/basic/function/multiDelete");
	}

	function fun_function_save() {
		$("#fm").form("submit", {
			url : "${ctx}/basic/function/update",
			success : function(data) {
				showInfo("保存成功!");
				$("#dlg").dialog("close");
				$("#grid").datagrid("load");
			}
		});
	}
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true">

		</table>
		<div id="tt" class="row">
		<div class="col-md-12">
			<shiro:hasPermission name="menu:update">
			<button id="btn-add" type="button" class="btn btn-primary" onclick="fun_function_add();">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="btn-edit" type="button" class="btn btn-primary" onclick="fun_function_edit();">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="menu:delete">
			<button id="btn-delete" type="button" class="btn btn-danger" onclick="fun_function_del();">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="menu:export">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导入
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="menu:import">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
			</shiro:hasPermission>
			</div>
		</div>
		<shiro:hasPermission name="menu:update">
			<div id="dlg" class="easyui-dialog" style="width: 620px; height: 210px; padding: 10px 20px" closed="true" buttons="#dlg-buttons">
				<form id="fm" method="post">
					<input id="id" type="hidden" name="id" />

					<table id="tbl">
						<tr>
							<td><label>功能编号:</label></td>
							<td><input name="functionNo" class="easyui-validatebox" data-options="required:true" /></td>
							<td><label>功能名称:</label></td>
							<td><input name="functionName" class="easyui-validatebox" data-options="required:true" /></td>
						</tr>
						<tr>
							<td><label>额外权限:</label></td>
							<td><input name="otherRights" class="easyui-validatebox" data-options="required:true" /></td>
						</tr>
					</table>

				</form>
			</div>
			<div id="dlg-buttons">
			<button id="add" type="button" class="btn btn-primary" onclick="fun_function_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</shiro:hasPermission>
	</div>
</body>
</html>
